﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dto;
using Model;

namespace DVT.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            
            using (Model.NewsDBEntities entities = new NewsDBEntities())
            {
                //top
                var news = entities.News.Where(x=>x.IsTop==1).Take(10).OrderByDescending(x=>x.ModifyDate).ToList();

                IList<NewsDto> newsDto = new List<NewsDto>();

                foreach (News n in news)
                {
                    NewsDto newsdto = new NewsDto();
                    newsdto.Id = n.Id;
                    newsdto.Content = n.NewsContent;
                    newsdto.Title = n.Title;
                    newsdto.PostDate = n.PostDate;
                    newsDto.Add(newsdto);
                }

                //most
                var mostnews = entities.News.Where(x => x.IsMost == 1).Take(10).OrderByDescending(x => x.ModifyDate).ToList();

                IList<NewsDto> mostnewsDto = new List<NewsDto>();

                foreach (News n in mostnews)
                {
                    NewsDto newsdto = new NewsDto();
                    newsdto.Id = n.Id;
                    newsdto.Content = n.NewsContent;
                    newsdto.Title = n.Title;
                    newsdto.PostDate = n.PostDate;
                    mostnewsDto.Add(newsdto);
                }

                ViewBag.NewsList = newsDto;
                ViewBag.MostNewsList = mostnewsDto;
            }
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

      
        public ActionResult Zsjh()
        {
            return View();
        }
    }
}
